package com.projectName.www.servlet;

import com.projectName.www.po.User;
import com.projectName.www.service.UserService;
import com.projectName.www.service.UserServiceImpl;
import com.projectName.www.util.MD5Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/registServlet")
public class RegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        request.setCharacterEncoding("utf-8");
        /**
         * 加载用户
         */

         String username=request.getParameter("username");
         String password = request.getParameter("password");
         String contact = request.getParameter("contact");
         String userType=request.getParameter("userType");

        User user=new User();
         user.setUserName(username);
         user.setPassword(password);
         user.setContact(contact);
         user.setUserType(Integer.parseInt(userType));
        System.out.println(user);//8888888888888888888888888888888888

        if (userType=="2"){
            //r如果是商家需要审核通过才可以
            user.setOnlinestatus(0);
        }else{
            user.setOnlinestatus(1);
        }

        UserService us= new UserServiceImpl();
        us.insert(user);
        //转发
        request.getRequestDispatcher("/login.jsp").forward(request,response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
